from fastapi import Depends, FastAPI, HTTPException
from sqlalchemy.orm import Session
from starlette.requests import Request
from typing import List
from pydantic import BaseModel
import datetime

import curd, models, schemas
from databases import SessionLocal, engine


app = FastAPI()

# 获取数据库
def get_db():
    try:
        db = SessionLocal()
        yield db
    finally:
        db.close()
        print('数据库已关闭')


@app.post("/tools/", response_model=schemas.NoticeBase)
def number(comment: schemas.NoticeBase, db:Session=Depends(get_db)):
    return curd.get_number(db=db, notice=comment)

# @app.get("/tools/1")
# async def notice_number():
#     import toMysql
#     db, cursor = toMysql.mysql_connect()
#     sql = "SELECT AlarmDate,AlarmTime,AlarmType,VarName FROM pause WHERE AlarmDate = '{0}'".format('2020-3-26')
#     cursor.execute(sql)
#     data = cursor.fetchall()
#     return {"data": data}

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app,host="127.0.0.1",port=8080)